//图片路径
export const imgService = function () {
    return 'http://10.0.0.44:8080'
}

/*
    时间戳转化为年-月-日 时-分-秒   timeStr 时间错   type  需要转化的类型
    2019-07-05   zhangjianyao
 */
export const famatDatesTimes = (timeStr,type) => {
    if(timeStr){
        var add0 = function(m){return m<10?'0'+m:m }
        var time = new Date(timeStr);
        var y = time.getFullYear();
        var m = time.getMonth()+1;
        var d = time.getDate();
        var h = time.getHours();
        var mm = time.getMinutes();
        var s = time.getSeconds();
        if(type){
            if(type == 'Y'){
               return y+'-'+add0(m)+'-'+add0(d)
            }
        }else{
            return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
        }

    }
};
/*
    手机号验证
    2019-07-05 zhangjianyao
*/
export const regPhoneNum = (phone) => {
    let phoneReg = /^1[3456789]\d{9}$/;
    if(phoneReg.test(phone)){
        return true;
    }else{
        return false;
    }
};

/*
    邮箱验证
    2019-07-05 zhangjianyao
*/
export const regEmailNum = (email) => {
    let eReg =/^([a-zA-Z]|[0-9])(\w|\-)+@[a-zA-Z0-9]+\.([a-zA-Z]{2,4})$/;
    if(eReg.test(email)){
        return true;
    }else{
        return false;
    }
};
/*
数字正则验证
*/
export const regNumber = (num) => {
    let eReg =/^[0-9]*$/;
    if(eReg.test(num)){
        return true;
    }else{
        return false;
    }
}

/*
    清空对象值
    2019-07-10 zhangjianyao
*/
export const clearObjValue = (obj) => {
    for(let key in obj){
        if(typeof obj[key]== 'object'){
            if(Array.isArray(obj[key])){
                obj[key] = [];
            }else{
                obj[key] = {};
            }
        }else{
            obj[key]  = ''
        }

    }
    return obj
};

/*
    数字和字母正则
    2019-07-18 lizheng
 */
export  const regNumStr =(obj) => {
    let strReg=/^[0-9a-zA-Z]*$/g;
    if (strReg.test(obj)) {
        return true;
    }else{
        return false;
    }
}

/*
   IP地址正则
    2019-07-19 lizheng
*/
export const regIpAddress = (obj) =>{
    let reg  = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
    if (reg.test(obj)){
        return true
    } else {
        return false
    }
}


/*
    如果子节点都选中了，只要把父节点的信息传出去；如果子节点只是部分选中,那么就把选中节点的信息传出去
    2022-02-15 zhangjianyao
*/
export const getSimpleCheckedNodes = (store) => {
    const checkedNodes = []
    const traverse = function(node) {
        const childNodes = node.root ? node.root.childNodes : node.childNodes
        childNodes.forEach(child => {
            if (child.checked) {
                checkedNodes.push(child.data)
            }
            if (child.indeterminate) {
                traverse(child)
            }
        })
    }
    traverse(store)
    return checkedNodes
}
/**
 * @description: 校验空值、null、undefined、[]
 * 2022-02-20 zhangjianyao
 */
export const verification = (val) => {
    let valString = val + ""
    let verificationType = ["", "null", "undefined"]
    return verificationType.includes(valString)
}
/**
 * @description: 校验空值、'' ,0 '0'
 * 2022-02-20 zhangjianyao
 */
export const verificationEmpty = (key) => {
   if(key){
   	return true
   }else{
   	if(key === '0' || key === 0){
   		return true
   	}else{
   		return false
   	}
   }
}
